**************************************************************
***** 		Probit models 				******
**************************************************************

/*
This replication code generates the robustness checks presented in the
online appendix for the paper
"Populism and De Facto Central Bank Independence"
(Gavin and Manger). All code is for Stata version 14.2
unless indicated.

Figures are generated using R 4.1.2. See the included R scripts.

*/
* Set this path to work on your own machine

global folder "~/path_to_replication_package"

cd $folder

use "$folder/D01_DeFactoCBI.dta", clear

tsset id quarterlydate

* Robustness checks shown in the table in the online appendix
* First stage of the IV model, Table A3 (1)

ivregress 2sls politicalPressure c.populism_vparty##c.economicRightParty (LagOutflowPercentGdp = iv_flows) ///
polity2 electionRunup imfCbiConditions debt2Gdp Lag3lnCpi DifflnExchRate Lag3DifflnGdp t t2 t3 if largeSample == 1, cluster(id) first

estimates store firstStage
est save defactoIv, replace

* Table A3 (2)
* First, include all countries, including those with a dependent CB, those that are
* autocracies, and those that impose full capital controls

probit politicalPressure c.populism_vparty##c.economicRightParty polity2 electionRunup imfCbiConditions ///
LagOutflowPercentGdp debt2Gdp Lag3lnCpi DifflnExchRate Lag3DifflnGdp t t2 t3, vce(cluster id)
estimates store allCountries
est save defactoIv, append

* Table A3 (3)
* all countries but now with the Hawkins et al. data

probit politicalPressure c.populistSpeechScore##c.economicRightParty polity2 electionRunup imfCbiConditions ///
LagOutflowPercentGdp debt2Gdp Lag3lnCpi DifflnExchRate Lag3DifflnGdp t t2 t3, vce(cluster id)
estimates store hawkins
est save defactoIv, append

* Table A3 (4)
* Modified model
* Include cases of hyperinflation

probit politicalPressure c.populism_vparty##c.economicRightParty polity2 electionRunup imfCbiConditions ///
LagOutflowPercentGdp debt2Gdp Lag3lnCpi DifflnExchRate Lag3DifflnGdp t t2 t3  ///
if emergingMarket  == 1 & capconindex == 0 & polity2 > 0 &  xrRegimeFine > 2 & lvau_garriga >= 0.4, vce(cluster id)

estimates store hyperinflators
est save defactoIv, append

* Table A3 (5)
* Include all countries that have their own currency, whether fixed exchange rate or not

probit politicalPressure c.populism_vparty##c.economicRightParty polity2 electionRunup imfCbiConditions ///
LagOutflowPercentGdp debt2Gdp Lag3lnCpi DifflnExchRate Lag3DifflnGdp t t2 t3  ///
if emergingMarket  == 1 & capconindex == 0 & polity2 > 0 & xrRegimeFine < 14 & lvau_garriga >= 0.4, vce(cluster id)

estimates store allfxregimes
est save defactoIv, append

esttab firstStage allCountries hawkins hyperinflators allfxregimes using "$folder/deFactoCbiAdditionalResults.tex", replace nogaps booktabs  ///
stats(p r2_p chi2 ll N N_clust, fmt(%9.2f %9.3f %9.0f %9.0f %9.0f %9.0f) labels("$ Prob > F $" "pseudo-$ R^2 $" "Chi-square" "Log-likelihood" "N" "Number of clusters")) ///
b(3) se(3) nonumbers noconstant mtitles ///
obslast order(populism_vparty populistSpeechScore economicRightParty c.populism_vparty#c.economicRightParty ///
c.populistSpeechScore#c.economicRightParty LagOutflowPercentGdp polity2 ///
electionRunup imfCbiConditions debt2Gdp Lag3lnCpi DifflnExchRate Lag3DifflnGdp t t2 t3) ///
addnotes("Multinomial probit model with Huber-White standard errors clustered by country, base category is 'no pressure'") ///
coeflabels(populism_vparty "Degree of populism" populistSpeechScore "Hawkins et al. populism" economicRightParty "Economic left-right scale" ///
c.populism_vparty#c.economicRightParty "Populism $\times$ Economic left-right scale" ///
c.populistSpeechScore#c.economicRightParty "Hawkins et al. populism $\times$ Economic left-right scale" ///
LagOutflowPercentGdp "Lagged capital outflows to GDP" ///
polity2 "Democracy" imfCbiConditions "IMF CB conditions" ///
electionRunup "Less than 12 months to election" debt2Gdp "Debt to GDP ratio" ///
Lag3lnCpi "Lagged inflation" DifflnExchRate "Lagged $ \Delta $ exchange rate" Lag3DifflnGdp "Lagged $ \Delta $ GDP" t " $ t$ " t2 "  $ t^2 $" t3 " $ t^3 $ ")


* check if the instrument contains trends (Christian and Barrett 2019) that could be a problem

ivreg2 politicalPressure c.populism_vparty##c.economicRightParty (LagOutflowPercentGdp = iv_flows) ///
polity2 electionRunup imfCbiConditions debt2Gdp Lag3lnCpi DifflnExchRate Lag3DifflnGdp t t2 t3 if largeSample == 1, cluster(id)
preserve
sort quarterlydate
by quarterlydate: egen averageNeighbourNetflows = mean(iv_flows)
sort id quarterlydate
tsset id quarterlydate
keep if iso == "ALB" & year >= 1996
dfuller averageNeighbourNetflows, lags(3) regress
* The verdict is that the series is stationary because the DF test statistic is smaller than the critical value at any critical value
restore
